package Chapter14_TypeInformation;

/**
 * Date: 2019/3/5
 * Time: 11:24
 * User: Driss.
 *
 * 14.7 动态代理
 * 简单代理示例
 */

interface Interface{
    void doSomething();
    void somethingElse(String args);
}

class RealObject implements Interface{
    public void doSomething() {
        System.out.println("doSomething");
    }

    public void somethingElse(String args) {
        System.out.println("somethingElse " + args);
    }
}


 class SimpleProxy implements Interface {

     private Interface proxied;
     public SimpleProxy(Interface proxied) {
         this.proxied = proxied;
     }

     public void doSomething() {
         System.out.println("SimpleProxy dosomthing");
         proxied.doSomething();
     }

     public void somethingElse(String args) {
         System.out.println("SimpleProxy SomethingElse " + args);
         proxied.somethingElse(args);
     }
 }

 public class SimpleProxyDemo {

    public static void consumer(Interface iface){
        iface.doSomething();
        iface.somethingElse("bonobo");
    }

     public static void main(String[] args) {
         consumer(new RealObject());
         consumer(new SimpleProxy(new RealObject()));
     }
}
